import util.GuiImg;
import util.util.FileSerialization;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Menu extends JPanel implements ActionListener {
    private Icon atmIcon3= GuiImg.getIcon("/imgs/buttonFind.jpg");
    private Icon atmIcon4= GuiImg.getIcon("/imgs/buttonGet.jpg");
    private Icon atmIcon5= GuiImg.getIcon("/imgs/buttonOff.jpg");
    private Icon atmIcon6= GuiImg.getIcon("/imgs/buttonSave.jpg");
    private Icon atmIcon7 = GuiImg.getIcon("/imgs/buttonModify.jpg");
    private Atm frame;
    private Check check;
    private JButton btnlogin4=new JButton(atmIcon5);
    private JButton btnlogin1=new JButton(atmIcon6);
    private JButton btnlogin2=new JButton(atmIcon4);
    private JButton btnlogin3=new JButton(atmIcon3);
    private JButton btnlogin5=new JButton(atmIcon7);
    private JButton btnlogin6=new JButton("转账");

    public Menu(Atm frame){
        this.frame=frame;
        this.setLayout(null);
        //存款按钮
        this.setOpaque(false);
        btnlogin1.setBounds(0,150,100,40);
        this.add(btnlogin1);
        btnlogin1.addActionListener(this);
        //取款按钮
        this.setOpaque(false);
        btnlogin2.setBounds(0,350,100,40);
        this.add(btnlogin2);
        btnlogin2.addActionListener(this);
        //查询按钮
        this.setOpaque(false);
        btnlogin3.setBounds(690,150,100,40);
        this.add(btnlogin3);
        btnlogin3.addActionListener(this);
        //改密按钮
        this.setOpaque(false);
        btnlogin5.setBounds(690,250,100,40);
        this.add(btnlogin5);
        btnlogin5.addActionListener(this);
        //转账按钮
        this.setOpaque(false);
        btnlogin6.setBounds(0,250,100,40);
        this.add(btnlogin6);
        btnlogin6.addActionListener(this);
        //退出按钮
        this.setOpaque(false);
        btnlogin4.setBounds(690,350,100,40);
        this.add(btnlogin4);
        btnlogin4.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        int num=0;
        if (e.getSource() == btnlogin4){
            frame.itin();
            frame.switchPanel("登录");
        }else if (e.getSource() == btnlogin1){
            frame.switchPanel("存款");
        }else if (e.getSource() == btnlogin2){
            frame.switchPanel("取款");
        }else if (e.getSource() == btnlogin3){
            frame.getCheck().getTextField2().setText(String.valueOf(frame.getUserArray().get(frame.getIndex()).getMoney()));
            frame.switchPanel("查询");
        }else if (e.getSource() == btnlogin5){
            frame.switchPanel("改密");
        }else if (e.getSource() == btnlogin6){
            frame.switchPanel("转账");
        }
    }

}
